package com.dts.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;

@WebFilter(urlPatterns = "/*", dispatcherTypes = {DispatcherType.REQUEST, DispatcherType.FORWARD})
public class MyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("Filter初始化");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        System.out.println("Before Filter: 请求处理前");
        chain.doFilter(request, response); // 继续执行后续过滤器或Servlet
        System.out.println("After Filter: 请求处理后");
    }

    @Override
    public void destroy() {
        System.out.println("Filter销毁");
    }
}